package com.android.support.lib.universal.sdk.alipay.libray;

import android.app.Activity;
import android.content.Context;

import com.android.support.lib.universal.http.NotifyUrl;

public class AlipayManager {
	// 商户PID
	public static final String PARTNER = "2088611460584203";
	// 商户收款账号
	public static final String SELLER = "xsmoke_game@sina.com";
	// RSA商户私钥，pkcs8格式
	public static final String RSA_PRIVATE = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKRaSYYQbA+5fBT1T4/LSa/S9nB3f0djC5ZLv7yqFFmpxxvc2wXwaNJ7D+U04M1eykrPiuto8f81k4c5EYbITqN8xU0uDI9xB+VIe/y+hZuI1WXO4LDiFW+4dFObqu5F/XInpBou1o/34zqtDXSV4EVt0K5TS6xAUsjupWeVt0BpAgMBAAECgYBboSLApcM5eRYesS2sY5AvgJR424aQjD3Xi1/YlZJG8wrZE+bghspKHuYbycFTfneWAePXn2jb+kjH6R9GX8LHKgqP144An2b0UJzTO/R8fv8pBmcqpepR1Kl2QsGMPdG1LT1wxobS31GaO7NtC+8a0dAwsXBwgMtketMVHqpCCQJBANp0bNyPxPLi3nnJBayBXqw3LHcVThPk1ADpAcBhBF4QGxRerf/sX7JGU4jVvX4j526kCKqt1EhC0j6ZDcRUKP8CQQDAmXo4XRQpictwLLk2XiQI4w4EthCrNQYqV5P3rhWTBhuZKMQrf5yBgBTphTb9+q1GWjaU669oQ35qCxcQCu6XAkBFH2vGypMWC6U7wdjSwci0E201bP9cmh5e/1t3hPs9zDjVVDQYc7HAFjKebIteG3xCbRL09rXh+4rNFd7eTYb/AkBT8lFgQcmo9UNzyDqOJOhF61lP2l9XkEv4pqV63ijPJWlgD3G5l+yKUV5MDmFSwDFIKcgCjtuscUanR+AsgOdPAkEAiklQpnzWVZnWOAWGC3TzwKTeYdTcwjDB3VnwWSKFljOjfZcM+81urDO5g7vTGr/vkHYWecPgQ1CZ1A3dK/AXLA==";
	// RSA支付宝公钥，对支付宝支付无用。但对二维码支付必须。
	public static final String RSA_PUBLIC = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";
	// 服务器回调地址
	public static final String notify_url = NotifyUrl.notify_url_alipay;

	private static AlipayManager sManager;
	private Context mContext;

	// 初始化
	public static AlipayManager getInstance(Context context) {
		if (context == null) {
			throw new IllegalArgumentException("argument is can not null!");
		}
		if (null == sManager) {
			sManager = new AlipayManager();
		}
		sManager.mContext = context;
		return sManager;
	}

	/**
	 * 调用SDK支付
	 * 
	 * @param subject
	 *            商品名
	 * @param body
	 *            商品描述
	 * @param total_fee
	 *            价格(1代表一元,0.01代表一分)
	 * @param out_trade_no
	 *            订单号，每一个订单号只能成功提交一次(失败的订单号可以重复提交)。
	 */
	public void pay(String subject, String body, String total_fee,
			String out_trade_no) {

		Alipay alipay = new Alipay((Activity) mContext);
		alipay.pay(subject, body, total_fee, out_trade_no);
	}

	// 回调事件
	private AlipayManagerListener mAlipayManagerListener;

	public void setAlipayManagerListener(AlipayManagerListener listener) {
		mAlipayManagerListener = listener;
	}

	public interface AlipayManagerListener {
		public void onPaySuccess();

		public void onPayFailed();
	}

	/**
	 * 支付成功回调
	 */
	public void onPaySuccess() {
		if (null != mAlipayManagerListener) {
			mAlipayManagerListener.onPaySuccess();
		}
	}

	/**
	 * 支付失败回调
	 */
	public void onPayFailed() {
		if (null != mAlipayManagerListener) {
			mAlipayManagerListener.onPayFailed();
		}
	}
}
